<div class="box box-solid no-margin box-show">
    @if($purchase->status == 1)
        <button class="btn btn-xs btn-default list-modal" data-id="{{ $id }}">批量更新包材单价</button>
        <div class="modal fade" id="tempModal" tabindex="-1">
            <div class="modal-dialog">
                <div class="modal-content">
                    <!-- 内容会加载到这里 -->
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
    @endif
    <div class="box-body">
        <div class="box-body table-responsive no-padding">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th>SKU</th>
                    <th width="10%">产品名称</th>
                    <th>备货数量</th>
                    <th>采购数量</th>
                    <th>采购单价</th>
                    <th>包材单价</th>
                    @if($purchase->status == 1)
                    <th>包材单价说明</th>
                    @endif
                    <th>采购金额</th>
                    <th>已收货数量</th>
                </thead>
                <tbody>
                @foreach($purchase->order_detail->sortBy('psku_id') as $item)
                    <tr>
                        <td>{{ $item->sku->psku_code }}</td>
                        <td>{{ $item->sku->psku_cn }}</td>
                        <td>{{ $item->apply_num }}</td>
                        @if($purchase->status == 1)
                            <td>
                                <a class="grid-editable-order_num"
                                   href="#"
                                   data-type="text"
                                   data-pk="{{ $item->id }}"
                                   data-url="{{ '/xqc/purchase/yj-order/'.$item->id }}"
                                   data-value="{{ $item->order_num }}">{{ $item->order_num }}</a>
                            </td>
                            <td>
                                <a class="grid-editable-unit_price"
                                   href="#"
                                   data-type="text"
                                   data-pk="{{ $item->id }}"
                                   data-url="{{ '/xqc/purchase/yj-order/'.$item->id }}"
                                   data-value="{{ $item->unit_price }}">{{ $item->unit_price }}</a>
                            </td>
                            <td>
                                <a class="grid-editable-pack_price"
                                   href="#"
                                   data-type="text"
                                   data-pk="{{ $item->id }}"
                                   data-url="{{ '/xqc/purchase/yj-order/'.$item->id }}"
                                   data-value="{{ $item->pack_price }}">{{ $item->pack_price }}</a>
                            </td>
                            <td>
                                <a class="grid-editable-pack_price_desc"
                                   href="#"
                                   data-type="text"
                                   data-pk="{{ $item->id }}"
                                   data-url="{{ '/xqc/purchase/yj-order/'.$item->id }}"
                                   data-value="{{ $item->pack_price_desc }}">{{ $item->pack_price_desc }}</a>
                            </td>
                        @else
                            <td>{{ $item->order_num }}</td>
                            <td>{{ $item->unit_price }}</td>
                            <td><a href="javascript:void(0)"
                                   data-container="body"
                                   data-toggle="popover"
                                   data-placement="top"
                                   data-html="true"
                                   data-trigger="hover"
                                   data-content="{{ $item->pack_price_desc }}">{{ $item->pack_price }}</a>
                            </td>
                        @endif
                        <td>{{ round(($item->order_num ?: 0) * ($item->unit_price ?: 0),3) }}</td>
                        <td>{{ $item->rgoods_num }}</td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
<script language="JavaScript" type="text/javascript">
    $(function () {
        $('[data-toggle="popover"]').popover();
        $('.grid-editable-order_num').editable(
            {
                "emptytext":"<i class=\"fa fa-pencil\"><\/i>",
                "showbuttons":false,
                "mode":"inline",
                "name":"detail-order_num",
                success: function(response, newValue) {
                    $.pjax.reload("#order-edit-form");
                }
            });
        $('.grid-editable-unit_price').editable(
            {
                "emptytext":"<i class=\"fa fa-pencil\"><\/i>",
                "showbuttons":false,
                "mode":"inline",
                "name":"detail-unit_price",
                success: function(response, newValue) {
                    $.pjax.reload("#order-edit-form");
                }
            });
        $('.grid-editable-pack_price').editable(
            {
                "emptytext":"<i class=\"fa fa-pencil\"><\/i>",
                "showbuttons":false,
                "mode":"inline",
                "name":"detail-pack_price"
            });
        $('.grid-editable-pack_price_desc').editable(
            {
                "emptytext":"<i class=\"fa fa-pencil\"><\/i>",
                "showbuttons":false,
                "mode":"inline",
                "name":"detail-pack_price_desc"
            });
        $('.list-modal').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            $("#tempModal").modal({
                remote : '/xqc/purchase/yj-order-modal?param=' + id + '&action=packPrice'
            });
        });
        $("#tempModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });
    });
</script>
